package com.xyp.homework;

/**
 * --- 加油，努力 ---
 *
 * @Author XYP
 * @Date 2024/8/5
 * @Desc 从想做到能做
 */
class Print1 {
    public static int num = 1;
    public static int word = 0;
    public static int numCount = 1;
    public static char wordCount = 'A';
    static  Object lock = new Object();
}
class PrintWord implements Runnable {

    @Override
    public void run() {
        while (true) {
            synchronized (Print1.lock) {
                if ((byte)Print1.wordCount > 90) {
                    break;
                } else {
                    if (Print1.word == 0) {
                        try {
                            Print1.lock.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    } else {
                        System.out.println(Print1.wordCount);
                        Print1.wordCount = (char)((byte)Print1.wordCount + 1);
                        Print1.word = 0;
                        Print1.num = 1;
                        Print1.lock.notifyAll();
                    }
                }
            }
        }
    }
}
class PrintNum implements Runnable {

    @Override
    public void run() {
        while (true) {
            synchronized (Print1.lock) {
                if (Print1.numCount > 52) {
                    break;
                } else {
                    if (Print1.num == 0) {
                        try {
                            Print1.lock.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    } else {
                        int count = 2;
                        for (int i = Print1.numCount; i <= 52; i++) {
                            System.out.print(i);
                            count--;
                            if (count == 0) {
                                break;
                            }
                        }
                        Print1.numCount += 2;
                        Print1.num = 0;
                        Print1.word = 1;
                        Print1.lock.notifyAll();
                    }
                }
            }
        }
    }
}
public class Demo3 {
    public static void main(String[] args) {

        new Thread(new PrintNum()).start();
        new Thread(new PrintWord()).start();

    }
}
